//
// Created on 2024/4/30.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef DIANPING_CAPI_DEMO_MODEL_H
#define DIANPING_CAPI_DEMO_MODEL_H
#include "common/Point.h"
#include "common/Size.h"
#include "common/Color.h"
#include "vector"

typedef enum{
    WATER_FLOW_VIEW_MODEL,
    FLOW_ITEM_VIEW_MODEL,
    INVALID_ITEM_VIEW_MODEL
}ViewModelTypeE;

class ViewModel : public std::enable_shared_from_this<ViewModel>{
protected:
    // common view model attribute mapping to view instance. 
    ViewModelTypeE modelType;
    Size m_size;
    Point m_startPosition;
    Color m_backgroundColor;
    std::shared_ptr<ViewModel> m_parent;
    std::vector<std::shared_ptr<ViewModel>> m_childs;
    
public:
    ViewModel(ViewModelTypeE type) {modelType = type; m_parent = NULL;}
    
    virtual ~ViewModel(){}
    
    ViewModelTypeE GetType() {return modelType;}
    virtual void setSize(Size size) {
        m_size = size;
    }
    
    virtual Size getSize() {return m_size;}
    
    virtual void setStartPosition(Point position) {
        m_startPosition = position;
    }
    
    virtual Point getStartPosition() {return m_startPosition;}
    
    virtual void setBackgroundColor(Color color){
        m_backgroundColor = color;
    }
    
    virtual Color getBackgroundColor() {return m_backgroundColor;}
    
    virtual void addChild(std::shared_ptr<ViewModel> model){
        m_childs.push_back(model);
        model->setParent(shared_from_this());
    }
    
    virtual std::vector<std::shared_ptr<ViewModel>>& getChilds(){
        return m_childs;
    }
    
    virtual void setParent(std::shared_ptr<ViewModel> model){
        m_parent = model;
    }
    
};

#endif //DIANPING_CAPI_DEMO_MODEL_H